﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Webdiver;

namespace AnyOffice.general.work_plan.manage
{
    public partial class index1 : ModulePage
    {
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        public string GetStatusDesc(int status)
        {
            switch (status)
            {
                case 0:
                    return "<font color=\"red\"><b>未开始</font>";

                case 1:
                    return "<font color=\"blue\"><b>进行中</font>";

                case 2:
                    return "<font color=\"green\"><b>完成</font>";
            }
            return "";
        }
        private void BindData()
        {
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            UserCache cache = new UserCache();
            ConfigManager manager = new ConfigManager();
            bool isAdministrator = cache.PrivId == manager.AdministratorPrivId;
            DataTable table = new PlanWorkDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false, base.User.Identity.Name, isAdministrator);
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.rptWorkPlan.DataSource = table;
            this.rptWorkPlan.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.AspNetPager1.PageSize = new ConfigManager().PageSize;
                UserCache cache = new UserCache();
                ConfigManager manager = new ConfigManager();
                bool isAdministrator = cache.PrivId == manager.AdministratorPrivId;
                DataTable table = new PlanWorkDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, 1, true, base.User.Identity.Name, isAdministrator);
                this.AspNetPager1.RecordCount = int.Parse(table.Rows[0][0].ToString());
                this.BindData();
                if (this.AspNetPager1.RecordCount == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无工作计划");
                }
            }
        }

    }
}
